﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotaHelp.Models;
using System.Web.UI;
using DotaHelp.Helpers;
using Sandbox.AddressBook.Web.Client.Application.Mvc;

namespace DotaHelp.Controllers
{
    
    public class HeroesController : Controller
    {
        DotaModel model = new DotaModel();

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            model.Dispose();
            
        }

        [ChildActionOnly]
        public ActionResult One(int id)
        {
            var hero = model.Heroes.FirstOrDefault(h => h.Id == id);
            return hero != null ? (ActionResult)PartialView(hero) : new ContentResult() { Content = "h" + id };
        }

		[ChildActionOnly]
		public ActionResult OneGif(int id)
        {
            var hero = model.Heroes.FirstOrDefault(h => h.Id == id);
            return hero != null ? (ActionResult)PartialView(hero) : new ContentResult() { Content = "H" + id };
        }

		

        [Sitemap(typeof(Hero))]
        public ActionResult Details(int id)
        {
			var hero = model.Heroes
				.Include("PurchaseHeroRules")
				.Include("PurchaseHeroRules.Item")
				.Include("Skills")				
				.First(h => h.Id == id);
            return View(hero);
        }

        [Sitemap]  
      	[OutputCache(Duration=600, Location=OutputCacheLocation.Server,VaryByCustom="User" )]
        public ActionResult List()
        {
            return View(model.Heroes);
        }
	
        [IfModified("HeroesOnlyListV2")]
        [OutputCache(Duration=600)]
		public ActionResult OnlyListV2()
		{
			return PartialView("OnlyList", model.Heroes);
		}

        [Sitemap]
        public ActionResult Animated()
        {
            return View(model.Heroes);
        }
                
		[OutputCache(Location=OutputCacheLocation.Server, Duration=600, VaryByCustom="User")]
        public ActionResult Title(int id)
        {
            return PartialView(model.Heroes.Include("Skills").First(h => h.Id == id));
        }

        [ChildActionOnly]
        public string Rating(int id, bool isPlus)
        {
            var hero = model.Heroes.First(h => h.Id == id);
            hero.Raiting += isPlus ? 1 : -1;
            model.SaveChanges();
            return hero.Raiting.ToString();
        }
 
		
    }
}
